<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*,java.util.*,support.*"%>
<%@page import="support.*,java.util.*"%>
<%@page import="support.*,java.util.*,java.sql.*,javax.sql.*"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ page import="java.sql.*,java.util.*,support.*"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Applications Page</title>
</head>
<body>
<head>
<style type="text/css">
<!--
#main {
 float: center;
 height: auto;
 width: 720;
}
#left {
 float: left;
 height: auto;
 width: 300;
}
#fxm {
 float: right;
 height: auto;
 width: 400;
}
-->
</style>

<script type="text/javascript">
	var old = -1;
	function toggle(value) {
		if (old != -1 && old != value) {
			var oBtnO = document.getElementById(old);
			oBtnO.value = 'Show Application';
		}

		var oDiv = document.getElementById('fxm')
		var oBtn = document.getElementById(value)

		if (oBtn.value == 'Show Application') {
			oDiv.style.display = 'block'
			oBtn.value = 'Hide Application'
		} else {
			oDiv.style.display = 'none'
			oBtn.value = 'Show Application'
		}
		old = value;
	}

	function showAppInfo(str) {
		var xmlHttp;

		xmlHttp = new XMLHttpRequest();
		if (xmlHttp == null) {
			alert("Your browser does not support AJAX!");
			return;
		}
		var url = "login/admins/applications-ajax.jsp";
		url = url + "?username=" + str;
		url = url + "&sid=" + Math.random();

		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
				var xmlDoc = document.getElementById("fxm");
				xmlDoc.innerHTML = xmlHttp.responseText;
			}
		}
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}

	function GetXmlHttpObject() {
		var xmlHttp = null;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp = new XMLHttpRequest();
		} catch (e) {
			// Internet Explorer
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		return xmlHttp;
	}
</script>
</head>

<%
	int i = 0;
%>
<div id="main">
<div id="left">
<logic:iterate id="nameId" name="adminAnaform" property="names">
	<table border="1">
		<tr>
			<td align="center">First</td>
			<td align="center">Middle</td>
			<td align="center">Last</td>
			<td align="center">Average</td>
			<td align="center">Status</td>
		</tr>
		<tr>
			<td align="center"><bean:write name="nameId" property="fname" /></td>
			<td align="center"><bean:write name="nameId" property="mname" /></td>
			<td align="center"><bean:write name="nameId" property="lname" /></td>
			<td align="center"><bean:write name="nameId" property="avg" /></td>
			<td align="center"><bean:write name="nameId" property="status" /></td>
		</tr>
	</table>

	<logic:equal name="nameId" property="status" value="Pending">
		<bean:define id="username" name="nameId" property="username" />

		<html:form action="/changeStatus">
			<input type="hidden" value='<%=(String) username%>' name="whichapp">
			<input type="submit" value="Accept" name="whatstatus">
			<input type="submit" value="Reject" name="whatstatus">
		</html:form>

		<form action="">
			<input type="hidden" value='<%=(String) username%>' name="whichapp">
			<input type=button value='Show Application'
				onclick='toggle("<%=i%>"); showAppInfo("<%=(String) username%>");'
				id='<%=i%>'">
		</form>
	</logic:equal>

	<logic:equal name="nameId" property="status" value="Accepted">
		<bean:define id="username" name="nameId" property="username" />

		<html:form action="/changeStatus">
			<input type="hidden" value='<%=(String) username%>' name="whichapp">
			<input type="submit" value="Reject" name="whatstatus">
			<input type="submit" value="Cancel" name="whatstatus">
		</html:form>

		<form action="">
			<input type="hidden" value='<%=(String) username%>' name="whichapp">
			<input type=button value='Show Application'
				onclick='toggle("<%=i%>"); showAppInfo("<%=(String) username%>");'
				id='<%=i%>'">
		</form>
	</logic:equal>

	<logic:equal name="nameId" property="status" value="Rejected">
		<bean:define id="username" name="nameId" property="username" />

		<html:form action="/changeStatus">
			<input type="hidden" value='<%=(String) username%>' name="whichapp">
			<input type="submit" value="Accept" name="whatstatus">
			<input type="submit" value="Cancel" name="whatstatus">
		</html:form>

		<form action="">
			<input type="hidden" value='<%=(String) username%>' name="whichapp">
			<input type=button value='Show Application'
				onclick='toggle("<%=i%>"); showAppInfo("<%=(String) username%>");'
				id='<%=i%>'">
		</form>
	</logic:equal>

	<p>
		<%
			i++;
		%>
</logic:iterate>

<html:form action="/Logoff">
		<html:submit value="Logoff" />
	</html:form>

</div>
	
<div id='fxm'></div>
</div>
</body>

</html>


